package com.zhan.ielts.task;

import com.zhan.ielts.dao.ParamDao;
import com.zhan.ielts.domain.Param;
import com.zhan.ielts.domain.SpeakingRecall;
import com.zhan.ielts.service.EmailService;
import com.zhan.ielts.service.SpeakingRecallService;
import com.zhan.ielts.utils.Contents;
import com.zhan.ielts.utils.SendSMSSelf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Component
public class SpeakingRecallPushJob {

    @Autowired
    SpeakingRecallService speakingRecallService;

    @Autowired
    private ParamDao paramDao;

    private Logger log = LoggerFactory.getLogger(SpeakingRecallPushJob.class);

    @Scheduled(cron = "0 0/2 8-23 * * ?")
    public void run() {
        String resourcePath = System.getenv("resources_path");
//        if ("pro".equals(resourcePath)) {
            try {
                log.info("start SpeakingRecallPushJob:" + new Date());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date date = null;
                try {
                    date = simpleDateFormat.parse("2016-09-20");
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                long timeStemp = date.getTime();
                SpeakingRecall query = new SpeakingRecall();
                query.setPushStatus("0");
                query.setStatus(0);
                query.setPublishTime(timeStemp);
                speakingRecallService.pushUnionMessage(query);
                log.info("end SpeakingRecallPushJob:" + new Date());
            } catch (Exception e) {
                e.printStackTrace();
                log.error("SpeakingRecallPushJob happen error");
            }
//        }
    }

}
